﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Register : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Page.Title = "新会员注册";

    }
    protected void btnReg_Click(object sender, EventArgs e)
    {
        try
        {
            string uid = tbUid.Text;//用户ID
            string umail = tbEmail.Text;
            string upwd =Md5.getMd5(tbPwd.Text);
            string uname = tbName.Text;
            string uadd = tbAdd.Text;
            string uphone = tbPhone.Text;

            DbAccess db = new DbAccess();
            ///验证用户ID是否已经存在;

            string sql = "select uid from UserInfo where uid='" + uid + "'";
            DataSet dsUser = db.GetDataSet(sql);
            if (dsUser.Tables[0].Rows.Count > 0)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('此会员已经存在')", true);


            }
            else
            { 
                //添加用户信息
                sql = "insert into UserInfo values('" + uid + "','" + upwd + "','" + umail + "','" + uname + "','" + uadd + "','" + uphone + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',0)";
                if (db.ExecuteSql(sql))
                {
                    Session["user"] = uid;
                    Response.Redirect("Default.aspx");
                }
                else
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('会员注册失败')", true);
            
            }


        }
        catch
        { 
        
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {

    }
}
